package baiguoyuan.kafka.simple;

public class FastSort {
    public static void main(String[] args) {
        System.out.println("快速排序");
        int[] a = {10,9,8,7,7,7,6,6,6,5,4,3,2,1};
        int start = 0;
        int end = a.length - 1;
        fastSort(a, start, end);
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
    }
    public static void fastSort(int[] a, int low, int high) {
        int start = low;
        int end = high;
        int key = a[low];

        while (start < end) {
            while (start < end && a[end] >= key) {
                end--;
            }
            if (start < end) {
                int temp = a[end];
                a[end] = a[start];
                a[start] = temp;
            }

            while (start < end && a[start] <= key) {
                start++;
            }
            if (start < end) {
                int temp = a[start];
                a[start] = a[end];
                a[end] = temp;
            }

        }
        if (start>low) {
            fastSort(a, low, start-1);
        }
        if (end < high) {
            fastSort(a, end+1, high);
        }
    }
}